export const baseURL = () => {
	const res = uni.getAccountInfoSync();
	switch (res.miniProgram.envVersion) {
		case 'develop':
			// 192.168.31.8
			return 'http://127.0.0.1:3001/api/front/';
		case 'develop':
			return 'http://localhost:3001/api/front/';
		case 'develop':
			return 'http://localhost:3001/api/front/';
		case 'develop':
			return 'http://localhost:3001/api/front/';
	}
}

const request = (method, url, data) => {
	return new Promise((resolve, reject) => {
		uni.request({
			method: method.toLocaleUpperCase(),
			url: baseURL() + url,
			data,
			success(res) {
				const r = res.data.data;
				if (r.code > 201) {
					reject(r.msg);
					return uni.showToast({
						title: r.msg,
						duration: 5000
					});
				}
				return resolve(r);
			},
			fail(err) {
				resolve(err)
			}
		})
	})
}

export default request;
